"use strict";
cc._RF.push(module, '2aa1a00GStDnrQOYAoyscZU', 'level_peopleArcheryBullet');
// scripts/levelBundles/level_PeopleArchery/unit/level_peopleArcheryBullet.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var level_PeopleArcheryUnitBase_1 = require("../base/level_PeopleArcheryUnitBase");
var peopleArcheryConst_1 = require("../const/peopleArcheryConst");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var level_PeopleArcheryBullet = /** @class */ (function (_super) {
    __extends(level_PeopleArcheryBullet, _super);
    function level_PeopleArcheryBullet() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.moveDis = 0;
        _this.maxDis = 0;
        _this.bulletAni = null;
        return _this;
    }
    level_PeopleArcheryBullet.prototype.setMaxDis = function (maxDis) {
        this.maxDis = maxDis;
    };
    level_PeopleArcheryBullet.prototype.initBullet = function () {
        this.moveDis = 0;
        this.isDeath = false;
        this.node.getComponent(cc.Collider).enabled = true;
        cc.Tween.stopAllByTarget(this.node);
        this.node.opacity = 255;
    };
    level_PeopleArcheryBullet.prototype.onEnable = function () {
        switch (this.level.role.profile) {
            case "0": {
                this.bulletAni.play("putong");
                break;
            }
            case "1": {
                this.bulletAni.play("xian");
                break;
            }
            case "2": {
                this.bulletAni.play("mo");
                break;
            }
        }
    };
    level_PeopleArcheryBullet.prototype.onCollisionEnter = function (other, self) {
        switch (other.tag) {
            case peopleArcheryConst_1.peopleArcheryUnitTag.enemy: {
                var os = other.node.getComponent(level_PeopleArcheryUnitBase_1.default);
                var criticalFlag = false;
                // if(!os.isDeath){
                var atk = this.atk;
                if (Math.random() < this.criticalPro) {
                    // 暴击 计算暴击伤害
                    var addition = Math.floor(atk * this.criticalAddition);
                    atk += addition;
                    criticalFlag = true;
                }
                var shotLeech = this.shotLeech;
                var hpRecover = 0;
                if (shotLeech > 0) {
                    //射击吸血 计算吸血量
                    hpRecover = atk * shotLeech;
                }
                if (hpRecover > 0) {
                    var data = { param_type: "0", option_param: hpRecover, reCoverMaxHp: "0", additionFlag: false };
                    this.level.parseDataAddPeople(data);
                }
                os.unitBeHurt(atk, "0", criticalFlag);
                this.unitDeath();
                this.unitDestroy();
                // }
                break;
            }
        }
    };
    level_PeopleArcheryBullet.prototype.update = function (dt) {
        // super.update(dt);
        if (this.level.gamePauseFlag || this.isDeath) {
            return;
        }
        var curFrameMoveDis = this.moveSpd * dt;
        this.moveDis += curFrameMoveDis;
        this.node.y += curFrameMoveDis;
        // 超过移动距离
        if (this.moveDis >= this.maxDis) {
            // 销毁
            this.unitDeath();
        }
    };
    level_PeopleArcheryBullet.prototype.unitDestroy = function () {
        this.level.bulletPool.put(this.node);
        this.node.removeFromParent(false);
    };
    __decorate([
        property({ type: cc.Animation, tooltip: "子弹动画" })
    ], level_PeopleArcheryBullet.prototype, "bulletAni", void 0);
    level_PeopleArcheryBullet = __decorate([
        ccclass
    ], level_PeopleArcheryBullet);
    return level_PeopleArcheryBullet;
}(level_PeopleArcheryUnitBase_1.default));
exports.default = level_PeopleArcheryBullet;

cc._RF.pop();